package com.ssy.lingxi.order.serviceimpl.web;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.model.vo.basic.request.PreOrderCacheKeyVO;
import com.ssy.lingxi.order.model.vo.basic.request.PreOrderCacheVO;
import com.ssy.lingxi.order.service.base.IBaseCacheService;
import com.ssy.lingxi.order.service.web.IPreOrderService;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 预下单相关接口实现类
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-20
 */
@Service
public class PreOrderServiceImpl implements IPreOrderService {
    @Resource
    private IBaseCacheService baseCacheService;

    /**
     * 缓存预下单
     *
     * @param headers Http头部信息
     * @param cacheVO 接口参数
     * @return 缓存结果
     */
    @Override
    public Wrapper<Void> cachePreOrder(HttpHeaders headers, PreOrderCacheVO cacheVO) {
        baseCacheService.checkUserFromCache(headers);
        baseCacheService.cachePreOrder(cacheVO.getKey(), cacheVO.getValue());
        return Wrapper.success();
    }

    /**
     * 查询预下单信息
     *
     * @param headers Http头部信息
     * @param keyVO 接口参数
     * @return 查询结果
     */
    @Override
    public Wrapper<String> getCachedPreOrder(HttpHeaders headers, PreOrderCacheKeyVO keyVO) {
        baseCacheService.checkUserFromCache(headers);
        return Wrapper.success(baseCacheService.getPreOrder(keyVO.getKey()));
    }

    /**
     * 删除预下单信息
     *
     * @param headers Http头部信息
     * @param keyVO 接口参数
     * @return 查询结果
     */
    @Override
    public Wrapper<Void> deleteCachedPreOrder(HttpHeaders headers, PreOrderCacheKeyVO keyVO) {
        baseCacheService.checkUserFromCache(headers);
        baseCacheService.deletePreOrder(keyVO.getKey());
        return Wrapper.success();
    }
}
